package com.jingan.nursinghome.regulatory.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;

import cn.android.support.v7.lib.sin.crown.base.BaseView;
import cn.android.support.v7.lib.sin.crown.utils.ProportionUtils;

/**
 * Created by 彭治铭 on 2017/10/17.
 */

public class MyTextView extends BaseView {
    public MyTextView(Context context) {
        super(context);
    }

    public MyTextView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    private void init() {
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        //super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        setMeasuredDimension(ProportionUtils.getInstance().adapterInt(200), ProportionUtils.getInstance().adapterInt(95));
    }

    String index, max;

    public void setIndexAndMax(String index, String max) {
        this.index = index;
        this.max = max;
        invalidate();
    }

    @Override
    public void draw(Canvas canvas) {
        super.draw(canvas);
        if (index == null || max == null) {
            return;
        }
        int textSize=ProportionUtils.getInstance().adapterInt(32);
        textPaint.setTextSize(textSize);
        textPaint.setTextAlign(Paint.Align.LEFT);

        int y=(getHeight()-textSize)/2+textSize;
        textPaint.setColor(Color.parseColor("#ADADAD"));
        String info="/"+max;
        int indexWidth = (int) textPaint.measureText(info, 0, info.length());
        int x=getWidth()-indexWidth;
        canvas.drawText(info,x,y,textPaint);

        textPaint.setColor(Color.parseColor("#2C2C2C"));
        indexWidth = (int) textPaint.measureText(index, 0, index.length());
        x=x-indexWidth;
        canvas.drawText(index,x,y,textPaint);
    }
}
